<template>
    <div>
        <h1>分类</h1>
        <div is-link @click="showPopup">展示弹出层</div>
        <van-popup v-model="show" round position="bottom" :style="{ height: '35%' }">
            <van-datetime-picker
                    v-model="currentDate"
                    type="datetime"
                    :min-date="minDate"
                    :max-date="maxDate"
                    @confirm="getTiem"
            />
        </van-popup>
        <h1>{{starttime1}}</h1>
    </div>
</template>

<script>
    import Vue from 'vue';
    import { Popup ,DatetimePicker } from 'vant';
    Vue.use(Popup).use(DatetimePicker);
  export default {
    name: "Category",
      data(){
        return{
            starttime1:'',
            show:false,
            minDate: new Date(2020, 0, 1),
            maxDate: new Date(2025, 10, 1),
            currentDate: new Date()
        }
      },
      methods:{
          showPopup() {
              this.show = true;
          },
          getTiem(){
              this.show = false;
              this.starttime =
                  this.currentDate.getFullYear() +
                  "年" +
                  (Number(this.currentDate.getMonth()) + 1) +
                  "月" +
                  this.currentDate.getDate() +
                  "日 " +
                  this.currentDate.getHours() +
                  ":" +
                  this.currentDate.getMinutes();
              let times = new Date(this.currentDate).getTime();
              this.starttime1 = this.dataFormat(times,true)
          },

          //->格式化时间戳
          dataFormat(time, type) {
            var dd = new Date(time);
            var y = dd.getFullYear();
            var m = dd.getMonth() + 1;
            var d = dd.getDate();
            var h = dd.getHours();
            var i = dd.getMinutes();
            var s = dd.getSeconds();
            m = m < 10 ? '0' + m : m;
            d = d < 10 ? '0' + d : d;
            h = h < 10 ? '0' + h : h;
            i = i < 10 ? '0' + i : i;
            s = s < 10 ? '0' + s : s;
            if(type) {
                return y + '-' + m + '-' + d + ' ' + h + ':' + i + ':' + s
            } else {
                return y + '-' + m + '-' + d
            }
    }



      }
  }
</script>

<style scoped>

</style>
